from scapy.all import send, sendp, sr, srp

##################
#the send funcion#
##################
def sendf(packet, amount=1, show=False):
    '''
    This funcion is used to send all kinds of packets which defined in this file to make a flood attack.
    It can use for all packets which defined in this file.
    
    packet: the packet you'd send
    amount: the time you'd send
    show: whether let the scapy.send function to print message to the screen
    '''
    if packet.send_type=='send':
        _sendf = send
    elif packet.send_type=='sendp':
        _sendf = sendp
    else:
        raise ValueError('Can not find the send_type!')
    
    if show:
        verbose = 1
    else:
        verbose = 0
    
    _sendf(
        (packet.remake() for i in range(amount)), verbose=verbose
    )

def srf(packet, amount=1, show=False, timeout=1):
    if packet.send_type=='send':
        _srf = srp
    elif packet.send_type=='sendp':
        _srf = sr
    else:
        raise ValueError('Can not find send_type')
    
    if show:
        verbose = 1
    else:
        verbose = 0
    
    return _srf(
        (packet.remake() for i in range(amount)), verbose=verbose, timeout=timeout
    )
